package cn.vonce.sqlbean.example.model.vo;

import cn.vonce.sql.annotation.SqlJoin;
import cn.vonce.sql.annotation.SqlTable;
import cn.vonce.sql.bean.Condition;
import cn.vonce.sql.bean.Select;
import cn.vonce.sql.define.JoinOn;
import cn.vonce.sql.enumerate.JoinType;
import cn.vonce.sqlbean.example.model.entity.Essay;
import cn.vonce.sqlbean.example.model.entity.User;
import cn.vonce.sqlbean.example.model.entity.sql.Essay$;
import cn.vonce.sqlbean.example.model.entity.sql.User$;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 文章关联用户昵称VO
 *
 * @author Jovi
 * @email imjovi@qq.com
 * @date 2023/10/27 17:19
 */
@Data
@SqlTable("t_essay")
public class EssayVO {

    // 关联用户条件 (注解1使用，可用于多条件)
    public static class EssayUserCondition implements JoinOn<Select> {
        @Override
        public void on(Condition<Select> condition) {
            condition.eq(User::getId, Essay::getUserId);
        }
    }

    @ApiModelProperty("用户id")
    private Long userId;

    @ApiModelProperty("标题")
    private String title;

    @ApiModelProperty("内容")
    private String content;

    @ApiModelProperty("用户昵称")
    @SqlJoin(type = JoinType.LEFT_JOIN, value = User$.nick_name, table = User$._tableName, on = EssayVO2.EssayUserCondition.class)
    //@SqlJoin(type = JoinType.LEFT_JOIN, value = User$.nick_name, table = User$._tableName, tableKeyword = User$.id, mainKeyword = Essay$.user_id)
    private String userName;

}
